﻿using Cms.Domain.Authentication;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cms.Tests.Unit.WebFramework.Infrastructure.Authentication
{
    [TestClass]
    public class ConversionTests
    {
        [TestMethod]
        public void ConvertUserBackAndForth()
        {
            AuthenticatedUser original = new AuthenticatedUser() { UserID = 1 };
            AuthenticatedUser result = ConvertUserBackAndForth(original);
            Assert.AreEqual(1, result.UserID);
            Assert.AreEqual(0, result.AdministratorID);
        }

        [TestMethod]
        public void ConvertAdministratorBackAndForth()
        {
            AuthenticatedUser original = new AuthenticatedUser() { AdministratorID = 111 };
            AuthenticatedUser result = ConvertUserBackAndForth(original);
            Assert.AreEqual(0, result.UserID);
            Assert.AreEqual(111, result.AdministratorID);
        }

        [TestMethod]
        public void ConvertBothUserAndAdministratorBackAndForth()
        {
            AuthenticatedUser original = new AuthenticatedUser() { AdministratorID = 111, UserID = 666 };
            AuthenticatedUser result = ConvertUserBackAndForth(original);
            Assert.AreEqual(666, result.UserID);
            Assert.AreEqual(111, result.AdministratorID);
        }

        private AuthenticatedUser ConvertUserBackAndForth(AuthenticatedUser original)
        {
            string compressed = Conversion.ToCompressedString(original);
            return Conversion.ToAuthenticatedUser(compressed);
        }
    }
}
